import axios from "axios";
import { removeToken} from "../utiles/token";

export function require(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        baseURL:'http://localhost:8009',
        params:config.data,
        method:'Get'
    });
    instant.interceptors.response.use(res => {
        return res.data
    },error => {return error});
    return instant(config)
}
export function get(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        baseURL:'http://localhost:8009',
        params:config.data,
        method:'Get',
        headers:config.headers,
    });
    instant.interceptors.response.use(res => {
        if(res.status !== 200){
            removeToken()
        }
        return res.data
    },error => {return error});

    return instant(config)
}

export function require2(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        method:"POST",
        baseURL:'http://localhost:8009',
        params:config.data,
        headers:config.headers
    });
    instant.interceptors.response.use(res => {
        return res.data
    },error => {return error});
    return instant(config)
}

export function post(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        method:"POST",
        baseURL:'http://localhost:8009',
        data:config.data,
        headers:config.headers
    });
    instant.interceptors.response.use(res => {
        return res.data
    },error => {return error});
    return instant(config)
}

export function del(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        method:"delete",
        baseURL:'http://localhost:8009',
        params:config.data,
    });
    instant.interceptors.response.use(res => {
        return res.data
    },error => {return error});
    return instant(config)
}

export function patch(config) {
    const instant = axios.create({
        // baseURL: ' http://192.168.137.1:8009',
        method:"PATCH",
        baseURL:'http://localhost:8009',
        headers:config.headers,
        data:config.data
    });
    instant.interceptors.response.use(res => {
        return res.data
    },error => {return error});
    return instant(config)
}
